package 博客管理系统;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.color.*;
import java.sql.*;
public class Del_bk extends JPanel implements ActionListener{
    JMenu JL = new JMenu("博客内容删除");
    JLabel number = new JLabel("用户ID");
    JTextField Number = new JTextField();
    JButton Del = new JButton("删除");
    JButton Reset = new JButton("重置");

    JButton Exit = new JButton("退出");
    String sql = "";

    public static void main(String[] args) {
        new Del_bk();
    }
    public void actionPerformed(ActionEvent e) {
        Connection con;
        Statement st;
        ResultSet rs;
        String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=BlogSystemLD";
        String userName="sa";
        String userPwd="123";
        String sql="select * from BlogContent";
        if (e.getSource() == Del) {
            Statement stm=null;
            Connection cot;
            try {
                con = DriverManager.getConnection(dbURL, userName, userPwd);
                st = con.createStatement();
                rs = st.executeQuery(sql);
                con.close();
                stm= con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE ,ResultSet.CONCUR_UPDATABLE );
                sql ="delete from User_View where id='"+Number.getText()+"'";
                int n = stm.executeUpdate(sql);
                if (n!=0)
                    JOptionPane.showMessageDialog(null, "删除成功！");
                else
                    JOptionPane.showMessageDialog(null, "删除失败！");
            } catch (SQLException e1) {
                JOptionPane.showMessageDialog(null, "此用户不存在！");
                e1.printStackTrace();
            }
        }
        if (e.getSource() == Reset) {
            Number.setText(null);
        }
        if (e.getSource() == Exit)
            this.setVisible(false);
    }
}
